package logic

import (
	"context"
	"gorm.io/gorm"
	"wechat/models/mysql"

	"wechat/wechatrpc/internal/svc"
	"wechat/wechatrpc/wechatrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateLogic {
	return &UpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UpdateLogic) Update(in *wechatrpc.UpdateRequest) (*wechatrpc.UpdateResponse, error) {
	// todo: add your logic here and delete this line

	wechat := mysql.Wechat{
		Model:   gorm.Model{ID: uint(in.Id)},
		Img:     in.Img,
		Name:    in.Name,
		Mobile:  in.Mobile,
		Address: in.Address,
	}

	mysql.DB.Debug().Save(&wechat)

	return &wechatrpc.UpdateResponse{
		Id: in.Id,
	}, nil
}
